package Duoxiancheng;

public class Buy {
    public static void main(String[] args) {
        Salesperson z=new Salesperson(5);
        Salesperson x=new Salesperson(10);
        Salesperson w=new Salesperson(20);
        Thread z1=new Thread(z,"赵四");
        Thread x1=new Thread(x,"谢大脚");
        Thread w1=new Thread(w,"王大拿");
        z1.setPriority(Thread.MAX_PRIORITY);
        x1.setPriority(Thread.NORM_PRIORITY);
        w1.setPriority(Thread.MIN_PRIORITY);
        z1.start();
        x1.start();
        w1.start();
    }
}

class Salesperson implements Runnable{
    private int ticket= 3;
    private int money;
    private int yue;

    public Salesperson(int money) {
        this.money = money;
    }

    @Override
    public void run() {
        Maipiao(money);
    }
    public void Maipiao(int a){
        if (a==5){
            ticket--;
            yue=a-5;
            System.out.println("恭喜"+Thread.currentThread().getName()+"拿到一张电影票");
            System.out.println("你的余额为："+yue);
        }
        if (ticket==0){
            System.out.println("电影票已经卖完了");
        }
    }
}
